package com.example.demo;

import com.example.demo.commom.AjaxResult;
import com.example.demo.controller.ArtController;
import com.example.demo.model.dto.art.ArtListDto;
import com.example.demo.model.dto.art.ArticlePubDto;
import com.example.demo.model.dto.art.OpArtDto;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.nio.file.Files;
import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:龙宝
 * Date:2024-05-16
 * Time:15:33
 */
@SpringBootTest
public class Art {
    @Autowired
    private ArtController artController;

    private String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjIiLCJleHAiOjE3MTY5OTA2MDksInVzZXJuYW1lIjoiY3lrIn0.ymqcztH0g_nxS7iV91IlUivl3BlRrQqVTcNk_kb0OkU";

    private ArticlePubDto dto = new ArticlePubDto();

    @Test
    public void pubArt() throws InterruptedException, IOException {
        dto.setTitle("明天生日1");
        dto.setContent("开心·");
        dto.setType(1);
        dto.setPubTime(0);
        List<MultipartFile> list = new ArrayList<>();
        // 照片文件的路径
        String filePath = "D:\\Project\\project\\redbook\\src\\test\\java\\com\\example\\demo\\pic\\1.png";
        // 读取文件内容到字节数组
        byte[] fileContent = Files.readAllBytes(new File(filePath).toPath());
        MockMultipartFile file = new MockMultipartFile("file", "1.png", "image/png", fileContent);
        list.add(file);
        list.add(file);
        dto.setPhotos(list);
        HttpServletRequest request = new MockHttpServletRequest();
        request.setAttribute("token", token);
        System.out.println(dto.getPhotos());
        artController.pub(request, dto);
    }

    @Test
    public void listArt(){
        ArtListDto artListDto = new ArtListDto();
        artListDto.setType(1);
        HttpServletRequest request = new MockHttpServletRequest();
        request.setAttribute("token", token);
//        AjaxResult result = artController.artList(request, artListDto);
//        System.out.println(result);
    }
    @Test
    public void listArt2(){
        ArtListDto artListDto = new ArtListDto();
        artListDto.setType(2);
        artListDto.setUserId(2);
        artListDto.setStart(0);
        artListDto.setLimit(1);
        HttpServletRequest request = new MockHttpServletRequest();
        request.setAttribute("token", token);
//        AjaxResult result = artController.artList(request, artListDto);
//        System.out.println(result);
    }
    @Test
    public void del(){
        HttpServletRequest request = new MockHttpServletRequest();
        request.setAttribute("token", token);
        AjaxResult result = artController.delArt(request, 1);
        System.out.println(result);
    }
    @Test
    public void album(){
        AjaxResult ajaxResult = artController.album(4);
        System.out.println(ajaxResult);
    }

    @Test
    public void likeAlbum(){
        HttpServletRequest request = new MockHttpServletRequest();
        request.setAttribute("token", token);
        OpArtDto dto = new OpArtDto();
        dto.setId(4);
        AjaxResult ajaxResult = artController.like(request, dto);
        System.out.println(ajaxResult);
    }

    @Test
    public void collectAlbum(){
        HttpServletRequest request = new MockHttpServletRequest();
        request.setAttribute("token", token);
        OpArtDto dto = new OpArtDto();
        dto.setId(4);
        AjaxResult ajaxResult = artController.collect(request, dto);
        System.out.println(ajaxResult);
    }
}
